#ifndef MESSAGETRAN_H
#define MESSAGETRAN_H


#include <string>

#define MAX_MESSAGETRAN_LEN     1024

using namespace std;

class MessageTran
{
public:
    unsigned char  m_packgeType;     //数据包头
    unsigned char  m_dataLen;        //数据长度
    unsigned char  m_readId;         //读写器地址
    unsigned char  m_cmd;            //数据包命令代码
    unsigned char* m_aryData;        //数据包命令参数，部分命令无参数
    unsigned char  m_check;          //校验和，除校验和本身外所有字节的校验和
    unsigned char* m_aryTranData;    //完整数据包
    int            m_aryDataLen;     //数据包命令参数长度
    int            m_aryTranDataLen; //完整数据包长度
    bool           m_isCK;           //校验是否成功
public:
    MessageTran();
    MessageTran(unsigned char readId, unsigned char cmd, unsigned char* aryData, int aryDataLen);
    MessageTran(unsigned char readId, unsigned char cmd);
    MessageTran(unsigned char* aryTranData, int aryTranDataLen);
    ~MessageTran();

public:
    int    GetAryTranData(unsigned char* pBuf, int& nSize);
    int    GetAryData(unsigned char* pBuf, int& nSize);
    unsigned char     GetDataLen();
    unsigned char     GetReadId();
    unsigned char     GetCmd();
    unsigned char     GetPackgeType();
    unsigned char     CheckSum(unsigned char* AryBuffer, int nStartPos, int nLen);
    int       GetAryDataLen();
    bool    IsCheck();
};

#endif // MESSAGETRAN_H
